﻿//using IBM.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace DoNet.ORM.Repository.EFCore
{
    public class MyDbContext : DbContext
    {
        private readonly DataBaseType dataBaseType;
        private readonly string connectionString;

        public MyDbContext(DataBaseType _dataBaseType, string _connectionString)
        {
            dataBaseType = _dataBaseType;
            connectionString = _connectionString;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                switch (dataBaseType)
                {
                    case DataBaseType.MySql:
                        optionsBuilder.UseMySQL(connectionString);
                        break;
                    case DataBaseType.SqlServer:
                        optionsBuilder.UseSqlServer(connectionString);
                        break;
                    case DataBaseType.Sqlite:
                        optionsBuilder.UseSqlite(connectionString);
                        break;
                    case DataBaseType.Oracle:
                        optionsBuilder.UseOracle(connectionString);
                        break;
                    case DataBaseType.PostgreSQL:
                        optionsBuilder.UseNpgsql(connectionString);
                        break;
                    case DataBaseType.Dm:
                        optionsBuilder.UseDm(connectionString);
                        break;
                    case DataBaseType.Kdbndp:
                        optionsBuilder.UseKdbndp(connectionString);
                        break;
                    //case DataBaseType.DB2:
                    //    //IBMDBServerType.LUW: 指定 DB2 LUW (Linux/Unix/Windows) 服务器类型
                    //    //IBMDBServerVersion: 根据实际 DB2 版本选择（如 LUW_11_01_2020）
                    //    optionsBuilder.UseDb2(connectionString, options => options.SetServerInfo(IBMDBServerType.LUW, IBMDBServerVersion.LUW_11_01_2020));
                    //    break;
                }
            }
        }
    }
}
